//
//  ChangePhoneController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/27.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "ChangePhoneController.h"
#import "LoginViewController.h"
#import "RootViewController.h"
@interface ChangePhoneController ()
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
- (IBAction)codeBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UITextField *passwordText;
@property (weak, nonatomic) IBOutlet UITextField *phoneText;

@property (weak, nonatomic) IBOutlet UITextField *codeText;
@end

@implementation ChangePhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"修改手机";
    self.tableView.tableFooterView = [UIView new];
    self.phoneLabel.text = [NSString stringWithFormat:@"当前手机号%@",[TokenManager getToken]];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tableView.emptyDataSetSource = nil;
    self.tableView.emptyDataSetDelegate = nil;
}




- (IBAction)codeBtn:(UIButton *)sender {
    
    [[ApiManager ShardInstance]codeuserID:[TokenManager getUserId] mobile:self.phoneText.text type:@"0" resultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [AuthCodeManager getValidCode:sender];
            [[ToastManager shardInstance]showToast:model.msg];
        }
        
    }];
}

- (IBAction)commitBtn:(BoardButton *)sender {
    
    [[ApiManager ShardInstance]editMobileid:[TokenManager getUserId] pass:self.passwordText.text mobile:self.phoneText.text captcha:self.codeText.text resultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [TokenManager removeUserId];
            [TokenManager removeToken];
            [self quitApp];
        }
        [[ToastManager shardInstance]showToast:model.msg];
    }];
    
}

-(void)quitApp{
    
    
    
    LoginViewController *loginVC = [LoginViewController loadStroyboard:[LoginViewController new]];
    
    UINavigationController * nav = [[RootViewController alloc] initWithRootViewController:loginVC];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:nav animated:YES completion:nil];
    
}
@end
